<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>密码策略信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<div style="margin: 10px">
    <table id="sysPwdStrategyTable" lay-filter="sysPwdStrategyTable"></table>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="sysPwdStrategyHeaderToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            <span>新增</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            <span>删除</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="clears">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
    </div>
    <form class="layui-form" action="" lay-filter="sysPwdStrategyQueryForm" style="margin-right: 30px;">
        <div class="layui-row" style="margin-top: 10px;">
            <div class="selch table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">状态</label>
                    <select name="Q_enable_N" class="filter-value">
                        <option value=""></option>
                        <option value="1">启用</option>
                        <option value="0">禁用</option>
                    </select>
                </div>
            </div>
        </div>
    </form>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="sysPwdStrategyRightToolsBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# if(d.enable == 0){ }}
    <button class="layui-btn layui-btn-xs" lay-event="runStrategy" >启用</button>
    {{# }else{ }}
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="runStrategy" >禁用</button>
    {{# } }}
</script>

<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>

<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter', 'form', 'common','totalFilter','commons','jquery','layer'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var commons = layui.commons;
        var layer = layui.layer;
        var $ = layui.jquery;
        var totalFilter = layui.totalFilter;
        common.tableSort('sysPwdStrategyTable');

        var tableH=commons.tabHeight('full-70');

        //第一个实例
        table.render({
            elem: '#sysPwdStrategyTable'
            ,height:tableH
            ,url: serverPath.systemPath + setter.sysLinkPath +'pwdStrategy/list'
            ,page: true //开启分页
            ,toolbar: '#sysPwdStrategyHeaderToolsBar'
            ,defaultToolbar: ['filter', 'print']
            ,method: 'get'
            ,autoSort: false //是否排序
            ,cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{type: 'checkbox', fixed: 'left'}
                ,{field: 'id', title: '主键',hide:true,sort:true, sortname: 'id'}
                ,{field: 'initPwd', title: '初始化密码',sort:true, sortname: 'init_pwd'}
                ,{field: 'forceChangeInitPwd', title: '强制修改初始化密码',hide:true,sort:true, sortname: 'force_change_init_pwd'}
                ,{field: 'pwdRule', title: '密码规则',sort:true, sortname: 'pwd_rule',templet:function (d) {
                        if(d.pwdRule == "2"){
                            return "数字加字母加特殊字符";
                        }else if(d.pwdRule == "1"){
                            return "数字加字母";
                        }else{
                            return "无限制";
                        }
                    }}
                ,{field: 'pwdLength', title: '密码长度',sort:true, sortname: 'pwd_length'}
                ,{field: 'validity', title: '密码有效期',hide:true,sort:true, sortname: 'validity'}
                ,{field: 'handleOverdue', title: '密码过期处理',sort:true, sortname: 'handle_overdue',templet:function (d) {
                        if(d.handleOverdue == "1"){
                            return "强制修改";
                        }else{
                            return "不处理";
                        }
                    }}
                ,{field: 'overdueRemind', title: '过期提醒',hide:true,sort:true, sortname: 'overdue_remind'}
                ,{field: 'verifyCodeAppear', title: '错误输入多少次验证码出现',hide:true,sort:true, sortname: 'verify_code_appear'}
                ,{field: 'errLockAccount', title: '错误输入多少次锁定账号',hide:true,sort:true, sortname: 'err_lock_account'}
                ,{field: 'enable', title: '状态',sort:true, sortname: 'enable_',templet:function (d) {
                        if(d.enable == "1"){
                            return "启用";
                        }else{
                            return "禁用";
                        }
                    }}
                ,{field: 'desc', title: '描述',hide:true,sort:true, sortname: 'desc_'}
                ,{
                    fixed: 'right',
                    align: 'center',
                    title: '管理',
                    toolbar: '#sysPwdStrategyRightToolsBar'
                }
            ]]
        });

        totalFilter.init('sysPwdStrategyTable');
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});

        function reflashQuery(isClear) {
            common.tableConditionRender("sysPwdStrategyTable","sysPwdStrategyQueryForm",{where:{}},isClear);
        }

        table.on('toolbar(sysPwdStrategyTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: ['新增数据'],
                        area: ['700px', '585px'],
                        content: serverPath.systemPath + setter.sysLinkPath +"pwdStrategy/view/add"
                    });
                    break;
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array+=data[i].id+",";
                    }
                    delFun(data,array);
                    break;
                case "query":
                    reflashQuery(false);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;
                case "clears":
                    reflashQuery(true);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;

            };
        });

        table.on('tool(sysPwdStrategyTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            switch(layEvent){
                case "edit":
                    layer.open({
                        type: 2,
                        area: ['700px', '585px'],
                        title: ['修改数据'],
                        content: serverPath.systemPath + setter.sysLinkPath + 'pwdStrategy/view/add?id='+data.id
                    });
                    break;
                case "del":
                    delFun(data,data.id);
                    break;
                case "runStrategy":
                    runFun(data.id,data.enable);
                    break;
            }
        });

        function delFun(data,id) {
            if (data.length === 0) {
                layer.msg('请先选择一行数据!');
            } else {
                layer.confirm('确定删除当前数据吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "pwdStrategy/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        }
                    })
                })
            }
        }
        function runFun(id,enable){
            var msg = enable == 0 ? '启用' : '禁用';
            var pEnable = enable == 0 ? 1 : 0;
            layer.confirm('确定'+msg+'当前策略吗?', function (index) {
                layer.close(index);
                $.ajax({
                    url: serverPath.systemPath + setter.sysLinkPath + "pwdStrategy/updateEnableState",
                    type: "get",
                    data: {id:id,enable:pEnable},
                    dataType: 'json',
                    success: function (data) {
                        layer.alert(data.msg);
                        //执行重载
                        reflashQuery(true);
                        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert(data.msg);
                        //执行重载
                        reflashQuery(true);
                        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    }
                })
            })
        }

        window.Initialization = function () {
            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        };
        /*刷新时间控件*/
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        common.tableSort("sysPwdStrategyTable",{show:window.Initialization});
    });
</script>
</body>
</html>